import React from 'react';
import { routerRedux } from 'dva';
import { Route, Switch } from 'react-router-dom';
import SecurityLayout from '@/layouts/SecurityLayout';
import SignLayout from '@/layouts/SignLayout';
import { getQueryObject, toQueryString } from '@/shared/utils/qsHelp';
import Globalize from '@/shared/services/i18n/Globalize';

const { ConnectedRouter } = routerRedux;

const rootRouter = ({ history }) => {
  const queryData = getQueryObject();
  if (!queryData.locale) {
    queryData.locale = Globalize.locale;
  }

  history.push({ search: toQueryString(queryData) });

  return (
    <ConnectedRouter history={history}>
      <Switch>
        <Route path="/sign" component={SignLayout} />
        <Route path="/" component={SecurityLayout} />
        <Route component={() => '这个页面走丢了'} />
      </Switch>
    </ConnectedRouter>
  );
};

export default rootRouter;
